package com.zelin.shop.web;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zelin.entity.SpecificationOptionEntity;
import com.zelin.entity.vo.SpecificationVoEntity;
import com.zelin.sellergoods.service.SpecificationOptionService;
import com.zelin.utils.PageUtils;
import com.zelin.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 
 *
 * @author WF
 * @email 2568783935@qq.com
 * @date 2021-07-23 21:10:35
 */
@RestController
@RequestMapping("/specificationoption")
public class SpecificationOptionController {
    @Reference(timeout = 5000)
    private SpecificationOptionService specificationOptionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("manager:specificationoption:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = specificationOptionService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 功能: 根据前台传入的模板表中的specIds对象查询规格及规格选项列表
     * 参数:
     * 返回值: com.zelin.utils.R
     * 时间: 2021/7/29 8:16
     */
    @RequestMapping("/findSpecList")
    public R findSpecList(@RequestBody List<SpecificationVoEntity> specs){
        List<SpecificationVoEntity> specList = specificationOptionService.findSpecList(specs);
        System.out.println("specList = " + specList);
        return R.ok().put("specList",specList);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("manager:specificationoption:info")
    public R info(@PathVariable("id") Long id){
		SpecificationOptionEntity specificationOption = specificationOptionService.getById(id);

        return R.ok().put("specificationOption", specificationOption);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("manager:specificationoption:save")
    public R save(@RequestBody SpecificationOptionEntity specificationOption){
		specificationOptionService.save(specificationOption);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("manager:specificationoption:update")
    public R update(@RequestBody SpecificationOptionEntity specificationOption){
		specificationOptionService.updateById(specificationOption);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("manager:specificationoption:delete")
    public R delete(@RequestBody Long[] ids){
		specificationOptionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
